def set_stage():
""" Sets up the stage for the game """
stage.set_background("soccerfield")
stage.disable_floor()
def add_player():
""" Adds a player to the stage for the user to control """
player = codesters.Sprite("player1")
player.go_to(0, -155)
return player
def add_ball():
""" Adds a ball to the stage and sets its attributes """
ball = codesters.Sprite("soccerball")
ball.set_y_speed(-8)
def main():
""" Sets up the program and calls other functions """
set_stage()
player = add_player()
add_ball()
main()
t = codesters.Teacher()
defs = t.find_block("def")
collision_event_handlers = t.find_text("event_collision")
ignore_defs = ['set_stage', 'main', 'add_player', 'add_ball']
def get_above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
def find_new_function(ignore_list, def_list):
""" Returns tuples of (line_number, function def) for any functions that aren't specified in ignore list """
return_list = []
for d in def_list:
count = 0
for i in ignore_list:
if i in d[1]:
break
else:
count += 1
if count == len(ignore_list):
return_list.append((d[0],d[1]))
return return_list
try:
new_functions = find_new_function(ignore_defs, defs)
def_name = new_functions[0][1]
def_line_num = new_functions[0][0]
def_indent = t.get_indent_at_line(def_line_num)
except:
def_name = "DNE"
def_line_num = "DNE"
def_indent = "DNE"
try:
above_def, distance = get_above_def(def_line_num, defs)
except:
above_def = "DNE"
distance = "DNE"
try:
tval2 = collision_event_handlers[0][1]
except:
tval2 = "DNE"
t1 = TestObjective()
t1.add_success("collision" in def_name, "Great job!")
t1.add_failure(def_name == "DNE", "Did you add Collision above the main() function?")
t2 = TestObjective()
t2.add_success("add_ball" in above_def and def_indent == 0, "Great job!")
t2.add_failure("add_ball" not in above_def, "Did you place Collision between add_ball() and main()?")
t2.add_failure(def_indent > 0, "Make sure that Collision is not indented within another function!")
t3 = TestObjective()
t3.add_success(tval2 == "DNE" and "collision" in def_name, "Great job!")
t3.add_failure(tval2 != "DNE", "Did you delete the event handler line?")
t3.add_failure(def_name == "DNE", "Did you add Collision above the main() function?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)